// cpp_manip.cpp
// Utilities for manipulating C++ code
#include "cpp_manip.h"

int function_start(ScintillaWin* sc, int il)
{
    // check whether we're actually inside a function
    if (sc->get_fold_level(il) == 0) return 0;

    // OK; find the begining of the function block
    while (sc->get_fold_level(il) != 0) il--;
    // get the first blank line before this
    while (il > 0 && ! sc->blank_line(il)) il--;
    return il+1;
}

bool function_extent(ScintillaWin* sc, long& lstart, long& lend, PosType pt)
{
    int lcurr = sc->current_line();
    lstart = function_start(sc,lcurr);
    if (lstart == 0) return false;  // we were _not_ inside a function!
    lend = lcurr;
    // find the last line of the block
    while (sc->get_fold_level(lend) != 0) lend++;
    // supply as position if required
    if (pt == AS_POS) {
        lstart = sc->get_pos_of_line_start(lstart);
        lend = sc->get_pos_of_line_end(lend);
    }
    return true;
}

